package com.jxiao.gsspringbootdocker.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.jxiao.gsspringbootdocker.model.User;
import com.jxiao.gsspringbootdocker.service.UserRepository;

@RestController
@RequestMapping(value = "/user")
public class AppController {

	@Autowired
	UserRepository repository;

	@RequestMapping(value = "/all", method = RequestMethod.GET)
	public List<User> findAll() {

		return repository.findAll();
	}

	@RequestMapping(value = "/findByName", method = RequestMethod.GET)
	public User findByName(String name) {

		return repository.findByName(name);
	}

	@RequestMapping(value = "/findByNameAndAge", method = RequestMethod.GET)
	public User findByNameAndAge(String name, Integer age) {

		return repository.findByNameAndAge(name, age);
	}

	@RequestMapping(value = "/save", method = RequestMethod.GET)
	public User save(User user) {

		return repository.save(user);
	}

}
